import openpyxl
from config import users_list


def writeExcel(file, sheet_index):
    workbook = openpyxl.load_workbook(file)
    worksheet = workbook.worksheets[0]
    nrows = worksheet.max_row
    ncols = worksheet.max_column
    print(nrows, ncols)

    # 根据平台已录入负责人email，增加部门和主要负责人两列数据
    worksheet.cell(2, 11).value = '部门'
    worksheet.cell(2, 12).value = '主要负责人'
    for row in range(3, nrows+1):
        email = worksheet.cell(row, 7).value
        for i in range(len(users_list)):
            for k, v in users_list[i].items():
                if email == v:
                    worksheet.cell(row, 11).value = users_list[i].get('department')
                    worksheet.cell(row, 12).value = users_list[i].get('owner')
    workbook.save(file)

if __name__ == '__main__':
    # file = 'log_2021-04-17_2021-04-20_sensitivedata.xlsx'
    file = 'old_processing_data/log_2021-05-01_2021-05-16_sensitivedata.xlsx'
    # data = get_data(file, 0)
    writeExcel = writeExcel(file, 0)
